<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<script>
  // console.log(new Promise())

  // 完成  resolve()
  // 失败  reject()
  // 都会改变 Promise 的状态
  /*
  let p1 = new Promise((resolve, reject) => {
    setTimeout(function () {
      /!*
      // 完成
      resolve({
        state: '200',
        data: {
          name: '张三',
          age: 18
        }
      })*!/
      // 失败
      reject('hahhah')
    }, 3000)
  }) // pending

  p1.then((res) => {
    // resolve
    console.log(res)
  }).catch((e) => {
    // reject
    console.log(e)
  })*/

  const p2 = function () {
    return new Promise((resolve, reject) => {
      // $.ajax({url, method, data})
      setTimeout(function () {
        // reject('hahhah')
        /*
        resolve({
          state: '200',
          data: {
            name: '张三',
            age: 18
          }
        })*/
      }, 3000)
    })
  }
  p2({}).then(res => {
    // resolve() -> success
    console.log(res)
  }).catch(e => {
    // reject() -> error
    console.log(e)
  }).finally(() => {
    // over
  })

  // promise().then(成功(), 失败())
  // promise().then(成功()).catch(失败())




</script>
</body>
</html>